package com.tgpms.web.excelTable.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PutMapping;
import javax.servlet.http.HttpServletRequest;
import javax.annotation.Resource;
import java.io.Serializable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.tgpms.auth.security.TokenService;
import com.tgpms.common.Result;
import com.tgpms.web.excelTable.entity.ExcelColumn;
import com.tgpms.web.excelTable.service.IExcelColumnService;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 动态表格列表 控制层
 * </p>
 *
 * @author newway
 * @since 2020-01-17
 */
@Api(value = "ExcelColumnController", tags = "动态表格列表相关接口")
@RestController
@RequestMapping("/ev/ExcelColumn")
public class ExcelColumnController {

	private final Logger log = LoggerFactory.getLogger(ExcelColumnController.class);
	
	@Resource
	private IExcelColumnService service;
	@Resource
	private TokenService tokenService;
	
	@ApiOperation(value = "新增动态表格列表接口",notes = "新增动态表格列表接口",httpMethod = "POST")
	@PostMapping(value = "/addExcelColumnInfo")
	public Result addExcelColumnInfo(@RequestBody ExcelColumn en,HttpServletRequest request) {
		log.info("新增动态表格列表接口接收到的参数为: "+en.toString());
		Result result = new Result();
		try{
			String insertName = tokenService.getUserName(request);
			en.setInsertUser(insertName);
			result = service.addExcelColumn(en,result);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			result.setMsg("增加异常");
			return result;
		}
		return result;
	}
	
	@ApiOperation(value = "修改动态表格列表接口",notes = "修改动态表格列表接口",httpMethod = "PUT")
	@PutMapping(value = "/updateExcelColumnInfo")
	public Result updateExcelColumnInfo(@RequestBody ExcelColumn en,HttpServletRequest request) {
		log.info("修改动态表格列表接口接收到的参数为: "+en.toString());
		Result result = new Result();
		try{
			String insertName = tokenService.getUserName(request);
			en.setModifyUser(insertName);
			result = service.updateExcelColumn(en,result);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			result.setMsg("修改异常");
			return result;
		}
		return result;
	}
	
	@ApiOperation(value = "删除动态表格列表接口",notes = "删除动态表格列表接口",httpMethod = "DELETE")
	@DeleteMapping(value = "/deleteExcelColumnInfo")
	public Result deleteExcelColumnInfo(@RequestParam Serializable id,HttpServletRequest request) {
		log.info("删除动态表格列表接口接收到的参数为: {id: "+id+" }");
		Result result = new Result();
		try{
			result = service.deleteExcelColumn(id,result);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			result.setMsg("删除异常");
			return result;
		}
		return result;
	}
}
